<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
		<title>课程专业管理</title>
		<link rel="icon" href="favicon.ico" type="image/ico">
		<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
		<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
		<meta name="author" content="yinqi">
		<link href="./css/bootstrap.min.css" rel="stylesheet">
		<link href="./css/materialdesignicons.min.css" rel="stylesheet">
		<link rel="stylesheet" href="./css/materialdesign.css" type="text/css">
		<link href="./css/style.min.css" rel="stylesheet">
	</head>
	 
	<script>
	
		
		
	</script>

	<body>

		<div class="col-xs-2" class="divcss5">
			<ul id="ztree1" class="ztree"></ul>
		</div>
 				
 			<input type="text" id="questionsTagName" />
			<input onclick="btn()" class="button" type="button" value="新增">
 
		<script type="text/javascript" src="./js/jquery.min.js"></script>
		<script type="text/javascript" src="./js/jquery.ztree.all.min.js"></script>
				<script type="text/javascript" src="js/jquery.cookie.js"></script>
		<script type="text/javascript">
			var zTreeObj;
			var setting = {
				view: {
					enable: true,
					showLine: true
				
				},
				async: {
					/*autoParam: ['pid'],
					url: 'http://localhost:9095/sysSubject/selectSysSubject'*/
				},
				isSimpleData: false, //数据是否采用简单 Array 格式，默认false
				treeNodeKey: "id", //在isSimpleData格式下，当前节点id属性
				treeNodeParentKey: "pId", //在isSimpleData格式下，当前节点的父节点id属性
				showLine: true, //是否显示节点间的连线
				callback: {
			
			      beforeRemove: beforeRemove,
					onRename: zTreeOnRename
				},
				edit: {
					enable: true, //单独设置为true时，可加载修改、删除图标
					editNameSelectAll: true,
				},
				data: {
					simpleData: {
						enable: true,
						idKey: "id",
						pIdKey: "pId",
						system: "system",
						rootPId: ""
					}
				},
			};


		

			$(function() {
				$.ajax({
					async: false,
					cache: false,
					type: 'GET',
					dataType: "json",
					url: "http://localhost:9095/admin/edutag/listTo", //请求的action路径
					data: {
						pid: ''
					},
					headers: {
						"token2": $.cookie("token2")
					},
					error: function() { //请求失败处理函数
						alert('请求失败');
					},
					success: function(msg) { //请求成功后处理函数
						console.log(msg)
						treeNodes = eval(msg.data); //把后台封装好的简单Json格式赋给treeNodes
					}
				});
			});
			
			//初始化节点
			$(document).ready(function() {
				$.fn.zTree.init($("#ztree1"), setting, treeNodes);
			});

			//修改
			function zTreeOnRename(event, treeId, treeNode, isCancel) {
				$.ajax({
					type:"post",
					url:"http://localhost:9095/admin/edutag/update",
					async:true,
					data:{
						'questionsTagId': treeNode.id,
					    'questionsTagName': treeNode.name
					},
					headers: {
						"token2": $.cookie("token2")
					},
					success:function(data, textStatus, xhr){
						if(textStatus == "success") {
							confirm("修改成功");
							return true;
						} else {
								confirm("修改失败");
							return false;
						}
					}
				});
				
				
				
				 
			}

			//添加字段
			function btn(){
			var questionsTagName=$("#questionsTagName").val();
			 var params={
			 	"questionsTagName": questionsTagName,
			 }
			 $.ajax({
						type: 'get',		
						url: 'http://localhost:9095/admin/edutag/save',
						data: params,
						headers: {
							"token2": $.cookie("token2")
						},
						dataType: "json",
						success: function(msg) {
							 alert("成功");
							 location.reload();
						},
						error:function(result){
							alert("error")
						}
					}); 
		}
			
			
			//删除节点
			function beforeRemove(treeId, treeNode) {			 	 
					var questionsTagId = treeNode.id;
					 
					$.ajax({
						async: false,
						cache: false,
						type: 'DELETE',
						dataType: "json",
						data:  
							{"id": questionsTagId},
						headers: {
							"token2": $.cookie("token2")
						},
						url: "http://localhost:9095/admin/edutag/delete", //请求的action路径
						error: function() { //请求失败处理函数
							confirm('请求失败');
						},
						success: function(msg) { //请求成功后处理函数。
							confirm("删除成功！");
							treeNodes = eval(msg.data); //把后台封装好的简单Json格式赋给treeNodes
						}
					});
				 
			}
			
		</script>
	</body>

</html>